﻿/*  
cd /projects/hsieh_project/proj_201809/code_1_data/
qsas data_1_cityind_sum.sas 5 & 
*/

libname hr "/projects/hsieh_project/proj_201809/data/";

%Let dir_out = /projects/hsieh_project/proj_201809/data/;

/*---------------------------------------------------------*/
/* Load Raw Data */
/*---------------------------------------------------------*/

%include "/projects/hsieh_project/proj_201809/code_1_data/m_read.sas" /source2;
%m_read(param_dev=1,param_lyear=0, param_czone=1, param_msa1983=1, param_drop=1);

/*
--------------------------------------------------------------------------------
Macros to Aggreate to desired level
*/

%include "/projects/hsieh_project/proj_201809/code_1_data/data_0_cityind_sum_core.sas" /source2;

%macro m_main(vgeo= );

%put --------------------------------------------------------------------------------;
%put Geo Variable: &vgeo.;

%cind_sum(dt_in=lbd, dt_out=lbd_cind_&vgeo., c_city=&vgeo., l_ind_perc=10 5 1, l_cind_rank=1);

data lbd_cind_&vgeo.;
  set lbd_cind_&vgeo.;
  drop _type_ _freq_;
run;

proc export data=lbd_cind_&vgeo. outfile="&dir_out./cityind_sum_&vgeo._all.dta" replace;
run;

%mend;

/*
--------------------------------------------------------------------------------
MSA and FIPS
*/

data lbd;
  set lbd;
  runif=runif_1;
run;

%m_main(vgeo=msa);
%m_main(vgeo=fips);


/*
--------------------------------------------------------------------------------
Communting zones
*/

%m_main(vgeo=czone);

/*
--------------------------------------------------------------------------------
Zip codes
*/

/* 5-dig zip */
data lbd;
   set lbd;
   if zipcode = "" then delete;
   zipcode = substr(zipcode,1,5);
run;

%m_main(vgeo=zipcode);


/* End of SAS file */
